// 创建整个应用的路由器
import VueRouter from "vue-router";
import About from "@/pages/About.vue";
import Home from "@/pages/Home.vue";
import News from "@/pages/News.vue";
import Message from "@/pages/Message.vue";
import Detail from "@/pages/Detail.vue";

// 创建并暴露一个路由器
export default new VueRouter({
    routes: [
        {
            name: 'guanyu',
            path: '/about',
            component: About
        },
        {
            path: '/home',
            component: Home,
            children: [
                {
                    path: 'news',
                    component: News
                },
                {
                    path: 'message',
                    component: Message,
                    children: [
                        {
                            name: 'xiangqing',
                            path: 'detail/:id/:title',
                            component: Detail,
                            // props第一种写法，值为对象，以props的形式传递给Detail组件,只能传递死数据
                            // props: {a:1,b:'hello'},

                            // props第二种写法，值为布尔值，如果为真，就会把路由组件收到的所有params参数以props的形式传递给Detail组件,注意：对query参数无效
                            // props: true,

                            // props第三种写法，值为一个函数
                            // props($route) { // 传递过来$route
                            //     return {
                            //         id: $route.params.id,
                            //         title: $route.params.title
                            //     }
                            // },
                            props({params:{id,title}}) { // 连续结构赋值
                                return {id,title}
                            }
                        }
                    ]
                }
            ]
        }
    ]
})